{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# (I) Downloading Continuous Data\n",
    "This notebook demonstrates the use of EQTransformer for downloading continuous data from seismic networks. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/Users/mostafamousavi/anaconda3/envs/test1/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    }
   ],
   "source": [
    "from EQTransformer.utils.downloader import makeStationList, downloadMseeds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can use help() to learn about input parameters of each fuunction. For instance:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function makeStationList in module EQTransformer.utils.downloader:\n",
      "\n",
      "makeStationList(client_list, min_lat, max_lat, min_lon, max_lon, start_time, end_time, channel_list=[], filter_network=[], filter_station=[])\n",
      "    Uses fdsn to find available stations in a specific geographical location and time period.  \n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    client_list: list\n",
      "        List of client names e.g. [\"IRIS\", \"SCEDC\", \"USGGS\"].\n",
      "                                \n",
      "    min_lat: float\n",
      "        Min latitude of the region.\n",
      "        \n",
      "    max_lat: float\n",
      "        Max latitude of the region.\n",
      "        \n",
      "    min_lon: float\n",
      "        Min longitude of the region.\n",
      "        \n",
      "    max_lon: float\n",
      "        Max longitude of the region.\n",
      "        \n",
      "    start_time: str\n",
      "        Start DateTime for the beginning of the period in \"YYYY-MM-DDThh:mm:ss.f\" format.\n",
      "        \n",
      "    end_time: str\n",
      "        End DateTime for the beginning of the period in \"YYYY-MM-DDThh:mm:ss.f\" format.\n",
      "        \n",
      "    channel_list: str, default=[]\n",
      "        A list containing the desired channel codes. Downloads will be limited to these channels based on priority. Defaults to [] --> all channels\n",
      "        \n",
      "    filter_network: str, default=[]\n",
      "        A list containing the network codes that need to be avoided. \n",
      "        \n",
      "    filter_station: str, default=[]\n",
      "        A list containing the station names that need to be avoided.\n",
      "    \n",
      "    Returns\n",
      "    ----------\n",
      "    stations_list.json: A dictionary containing information for the available stations.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(makeStationList)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1) Finding the availabel stations "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Defining the location and time period of interest:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "MINLAT=35.50\n",
    "MAXLAT=35.60\n",
    "MINLON=-117.80\n",
    "MAXLON=-117.40\n",
    "STIME=\"2019-09-01 00:00:00.00\"\n",
    "ETIME=\"2019-09-02 00:00:00.00\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can limit your data types (e.g. broadband, short period, or strong motion) of interest:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "CHANLIST=[\"HH[ZNE]\", \"HH[Z21]\", \"BH[ZNE]\", \"EH[ZNE]\", \"SH[ZNE]\", \"HN[ZNE]\", \"HN[Z21]\", \"DP[ZNE]\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This will download the information on the stations that are available based on your search criteria. You can filter out the networks or stations that you are not interested in, you can find the name of the appropriate client for your request from here:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GS--CA06\n",
      "GS--CA10\n",
      "PB--B921\n",
      "ZY--SV08\n"
     ]
    }
   ],
   "source": [
    "makeStationList(client_list=[\"SCEDC\"],  \n",
    "                  min_lat=MINLAT,\n",
    "                  max_lat=MAXLAT,\n",
    "                  min_lon=MINLON, \n",
    "                  max_lon=MAXLON,                      \n",
    "                  start_time=STIME, \n",
    "                  end_time=ETIME,\n",
    "                  channel_list=CHANLIST,\n",
    "                  filter_network=[\"SY\"],\n",
    "                  filter_station=[])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A jason file (\"stataions_list.json\") should have been created in your current directory. This contains information for the available stations (i.e. 4 stations in this case). Next, you can download the data for the available stations using the following function and script. This may take a few minutes."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2) Downloading the data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can define multipel clients as the source:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:56:18,966] - obspy.clients.fdsn.mass_downloader - INFO: Initializing FDSN client(s) for SCEDC, IRIS.\n",
      "[2020-06-30 12:56:19,092] - obspy.clients.fdsn.mass_downloader - INFO: Successfully initialized 2 client(s): SCEDC, IRIS.\n",
      "[2020-06-30 12:56:19,094] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 0\n",
      "[2020-06-30 12:56:19,095] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 0\n",
      "[2020-06-30 12:56:19,097] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Requesting unreliable availability.\n",
      "[2020-06-30 12:56:19,095] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Requesting unreliable availability.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "####### There are 4 stations in the list. #######\n",
      "======= Working on CA06 station.======= Working on CA10 station.\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:56:19,345] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully requested availability (0.25 seconds)\n",
      "[2020-06-30 12:56:19,348] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully requested availability (0.25 seconds)\n",
      "[2020-06-30 12:56:19,350] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Found 0 stations (0 channels).\n",
      "[2020-06-30 12:56:19,352] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Found 1 stations (3 channels).\n",
      "[2020-06-30 12:56:19,353] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - No data available.\n",
      "[2020-06-30 12:56:19,354] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Will attempt to download data from 1 stations.\n",
      "[2020-06-30 12:56:19,355] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 0\n",
      "[2020-06-30 12:56:19,357] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Requesting reliable availability.\n",
      "[2020-06-30 12:56:19,359] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 3 time intervals/channels before downloading: NEEDS_DOWNLOADING\n",
      "[2020-06-30 12:56:19,397] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully requested availability (0.04 seconds)\n",
      "[2020-06-30 12:56:19,399] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Found 0 stations (0 channels).\n",
      "[2020-06-30 12:56:19,399] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - No data available.\n",
      "[2020-06-30 12:56:19,400] - obspy.clients.fdsn.mass_downloader - INFO: ============================== Final report\n",
      "[2020-06-30 12:56:19,402] - obspy.clients.fdsn.mass_downloader - INFO: 0 MiniSEED files [0.0 MB] already existed.\n",
      "[2020-06-30 12:56:19,402] - obspy.clients.fdsn.mass_downloader - INFO: 0 StationXML files [0.0 MB] already existed.\n",
      "[2020-06-30 12:56:19,403] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 0 MiniSEED files [0.0 MB].\n",
      "[2020-06-30 12:56:19,404] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 0 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:56:19,405] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 0 MiniSEED files [0.0 MB].\n",
      "[2020-06-30 12:56:19,405] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 0 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:56:19,406] - obspy.clients.fdsn.mass_downloader - INFO: Downloaded 0.0 MB in total.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "** done with --> CA10 -- GS -- 2019-09-01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:56:45,411] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 0\n",
      "[2020-06-30 12:56:45,411] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Requesting unreliable availability.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "======= Working on B921 station.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:56:45,678] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully requested availability (0.27 seconds)\n",
      "[2020-06-30 12:56:45,716] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Found 1 stations (3 channels).\n",
      "[2020-06-30 12:56:45,716] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Will attempt to download data from 1 stations.\n",
      "[2020-06-30 12:56:45,718] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 3 time intervals/channels before downloading: NEEDS_DOWNLOADING\n",
      "[2020-06-30 12:57:00,363] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:57:00,617] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:57:01,004] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:57:01,005] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Launching basic QC checks...\n",
      "[2020-06-30 12:57:01,036] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Downloaded 27.1 MB [1817.30 KB/sec] of data, 0.0 MB of which were discarded afterwards.\n",
      "[2020-06-30 12:57:01,037] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 3 time intervals/channels after downloading: DOWNLOADED\n",
      "[2020-06-30 12:57:07,603] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 'downloads_mseedsxml/B921/PB.B921.xml'.\n",
      "[2020-06-30 12:57:07,606] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Downloaded 1 station files [0.0 MB] in 6.6 seconds [3.83 KB/sec].\n",
      "[2020-06-30 12:57:07,607] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 1\n",
      "[2020-06-30 12:57:07,608] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Requesting reliable availability.\n",
      "[2020-06-30 12:57:07,762] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully requested availability (0.15 seconds)\n",
      "[2020-06-30 12:57:07,788] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Found 1 stations (3 channels).\n",
      "[2020-06-30 12:57:07,789] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - No new data available after discarding already downloaded data.\n",
      "[2020-06-30 12:57:07,790] - obspy.clients.fdsn.mass_downloader - INFO: ============================== Final report\n",
      "[2020-06-30 12:57:07,790] - obspy.clients.fdsn.mass_downloader - INFO: 0 MiniSEED files [0.0 MB] already existed.\n",
      "[2020-06-30 12:57:07,791] - obspy.clients.fdsn.mass_downloader - INFO: 0 StationXML files [0.0 MB] already existed.\n",
      "[2020-06-30 12:57:07,792] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 3 MiniSEED files [27.1 MB].\n",
      "[2020-06-30 12:57:07,793] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 1 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:57:07,793] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 0 MiniSEED files [0.0 MB].\n",
      "[2020-06-30 12:57:07,794] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 0 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:57:07,795] - obspy.clients.fdsn.mass_downloader - INFO: Downloaded 27.1 MB in total.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "** done with --> B921 -- PB -- 2019-09-01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:57:34,800] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 0\n",
      "[2020-06-30 12:57:34,801] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Requesting unreliable availability.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "======= Working on SV08 station.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:57:35,262] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully requested availability (0.46 seconds)\n",
      "[2020-06-30 12:57:35,264] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Found 1 stations (3 channels).\n",
      "[2020-06-30 12:57:35,265] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Will attempt to download data from 1 stations.\n",
      "[2020-06-30 12:57:35,267] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 3 time intervals/channels before downloading: NEEDS_DOWNLOADING\n",
      "[2020-06-30 12:57:35,476] - obspy.clients.fdsn.mass_downloader - ERROR: Client 'SCEDC' - Service responds: Internal server error\n",
      "Detailed response of server:\n",
      "\n",
      "Error 500: STP clients exceeded. Please try again later\n",
      "More Details:\n",
      "handler exited, code: 1  reason: Internal Server Error\n",
      "Request:\n",
      "http://service.scedc.caltech.edu/fdsnws/dataselect/1/query\n",
      "Request Submitted:\n",
      "2020/06/30 19:57:36 UTC\n",
      "Service version:\n",
      "Service: fdsnws-dataselect  version: 1.1.0\n",
      "[2020-06-30 12:57:50,093] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:57:51,280] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:57:51,281] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Launching basic QC checks...\n",
      "[2020-06-30 12:57:51,300] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Downloaded 18.2 MB [1162.13 KB/sec] of data, 0.0 MB of which were discarded afterwards.\n",
      "[2020-06-30 12:57:51,301] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 1 time intervals/channels after downloading: DOWNLOAD_FAILED\n",
      "[2020-06-30 12:57:51,302] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 2 time intervals/channels after downloading: DOWNLOADED\n",
      "[2020-06-30 12:57:57,876] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Successfully downloaded 'downloads_mseedsxml/SV08/ZY.SV08.xml'.\n",
      "[2020-06-30 12:57:57,882] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Downloaded 1 station files [0.0 MB] in 6.6 seconds [0.63 KB/sec].\n",
      "[2020-06-30 12:57:57,884] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 1\n",
      "[2020-06-30 12:57:57,885] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Requesting reliable availability.\n",
      "[2020-06-30 12:57:57,965] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - No data available for request.\n",
      "[2020-06-30 12:57:57,966] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - No data available.\n",
      "[2020-06-30 12:57:57,967] - obspy.clients.fdsn.mass_downloader - INFO: ============================== Final report\n",
      "[2020-06-30 12:57:57,967] - obspy.clients.fdsn.mass_downloader - INFO: 0 MiniSEED files [0.0 MB] already existed.\n",
      "[2020-06-30 12:57:57,968] - obspy.clients.fdsn.mass_downloader - INFO: 0 StationXML files [0.0 MB] already existed.\n",
      "[2020-06-30 12:57:57,970] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 2 MiniSEED files [18.2 MB].\n",
      "[2020-06-30 12:57:57,970] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 1 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:57:57,971] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 0 MiniSEED files [0.0 MB].\n",
      "[2020-06-30 12:57:57,972] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 0 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:57:57,972] - obspy.clients.fdsn.mass_downloader - INFO: Downloaded 18.2 MB in total.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "** done with --> SV08 -- ZY -- 2019-09-01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[2020-06-30 12:58:02,300] - obspy.clients.fdsn.mass_downloader - ERROR: Client 'SCEDC' - Service responds: Internal server error\n",
      "Detailed response of server:\n",
      "\n",
      "Error 500: STP fatal error. Please try again later.\n",
      "More Details:\n",
      "handler exited, code: 1  reason: Internal Server Error\n",
      "Request:\n",
      "http://service.scedc.caltech.edu/fdsnws/dataselect/1/query\n",
      "Request Submitted:\n",
      "2020/06/30 19:58:03 UTC\n",
      "Service version:\n",
      "Service: fdsnws-dataselect  version: 1.1.0\n",
      "[2020-06-30 12:58:02,721] - obspy.clients.fdsn.mass_downloader - ERROR: Client 'SCEDC' - Service responds: Internal server error\n",
      "Detailed response of server:\n",
      "\n",
      "Error 500: STP fatal error. Please try again later.\n",
      "More Details:\n",
      "handler exited, code: 1  reason: Internal Server Error\n",
      "Request:\n",
      "http://service.scedc.caltech.edu/fdsnws/dataselect/1/query\n",
      "Request Submitted:\n",
      "2020/06/30 19:58:04 UTC\n",
      "Service version:\n",
      "Service: fdsnws-dataselect  version: 1.1.0\n",
      "[2020-06-30 12:58:05,175] - obspy.clients.fdsn.mass_downloader - ERROR: Client 'SCEDC' - Service responds: Internal server error\n",
      "Detailed response of server:\n",
      "\n",
      "Error 500: STP fatal error. Please try again later.\n",
      "More Details:\n",
      "handler exited, code: 1  reason: Internal Server Error\n",
      "Request:\n",
      "http://service.scedc.caltech.edu/fdsnws/dataselect/1/query\n",
      "Request Submitted:\n",
      "2020/06/30 19:58:06 UTC\n",
      "Service version:\n",
      "Service: fdsnws-dataselect  version: 1.1.0\n",
      "[2020-06-30 12:58:05,176] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Launching basic QC checks...\n",
      "[2020-06-30 12:58:05,177] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Downloaded 0.0 MB [0.00 KB/sec] of data, 0.0 MB of which were discarded afterwards.\n",
      "[2020-06-30 12:58:05,178] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Status for 3 time intervals/channels after downloading: DOWNLOAD_FAILED\n",
      "[2020-06-30 12:58:05,179] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - No station information to download.\n",
      "[2020-06-30 12:58:05,179] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - No data could be downloaded.\n",
      "[2020-06-30 12:58:05,180] - obspy.clients.fdsn.mass_downloader - INFO: Total acquired or preexisting stations: 0\n",
      "[2020-06-30 12:58:05,181] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Requesting reliable availability.\n",
      "[2020-06-30 12:58:05,251] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully requested availability (0.07 seconds)\n",
      "[2020-06-30 12:58:05,254] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Found 1 stations (3 channels).\n",
      "[2020-06-30 12:58:05,255] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Will attempt to download data from 1 stations.\n",
      "[2020-06-30 12:58:05,256] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Status for 3 time intervals/channels before downloading: NEEDS_DOWNLOADING\n",
      "[2020-06-30 12:58:16,784] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:58:17,034] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:58:17,039] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully downloaded 1 channels (of 1)\n",
      "[2020-06-30 12:58:17,040] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Launching basic QC checks...\n",
      "[2020-06-30 12:58:17,148] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Downloaded 25.2 MB [2185.77 KB/sec] of data, 0.0 MB of which were discarded afterwards.\n",
      "[2020-06-30 12:58:17,148] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Status for 3 time intervals/channels after downloading: DOWNLOADED\n",
      "[2020-06-30 12:58:17,224] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Successfully downloaded 'downloads_mseedsxml/CA06/GS.CA06.xml'.\n",
      "[2020-06-30 12:58:17,235] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Downloaded 1 station files [0.1 MB] in 0.1 seconds [1043.95 KB/sec].\n",
      "[2020-06-30 12:58:17,236] - obspy.clients.fdsn.mass_downloader - INFO: ============================== Final report\n",
      "[2020-06-30 12:58:17,237] - obspy.clients.fdsn.mass_downloader - INFO: 0 MiniSEED files [0.0 MB] already existed.\n",
      "[2020-06-30 12:58:17,238] - obspy.clients.fdsn.mass_downloader - INFO: 0 StationXML files [0.0 MB] already existed.\n",
      "[2020-06-30 12:58:17,239] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 0 MiniSEED files [0.0 MB].\n",
      "[2020-06-30 12:58:17,240] - obspy.clients.fdsn.mass_downloader - INFO: Client 'SCEDC' - Acquired 0 StationXML files [0.0 MB].\n",
      "[2020-06-30 12:58:17,242] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 3 MiniSEED files [25.2 MB].\n",
      "[2020-06-30 12:58:17,243] - obspy.clients.fdsn.mass_downloader - INFO: Client 'IRIS' - Acquired 1 StationXML files [0.1 MB].\n",
      "[2020-06-30 12:58:17,244] - obspy.clients.fdsn.mass_downloader - INFO: Downloaded 25.2 MB in total.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "** done with --> CA06 -- GS -- 2019-09-01\n"
     ]
    }
   ],
   "source": [
    "downloadMseeds(client_list=[\"SCEDC\", \"IRIS\"], \n",
    "          stations_json='station_list.json', \n",
    "          output_dir=\"downloads_mseeds\", \n",
    "          start_time=STIME, \n",
    "          end_time=ETIME, \n",
    "          min_lat=MINLAT, \n",
    "          max_lat=MAXLAT, \n",
    "          min_lon=MINLON, \n",
    "          max_lon=MAXLON,\n",
    "          chunk_size=1,\n",
    "          channel_list=[],\n",
    "          n_processor=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above will download the continous data (either in MiniSeed or SAC) and save them into individual folders for each station insider your defined output directory (i.e. downloads_mseeds)."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
